package fileRandW;

import java.io.*;


import binaryTreePackage.BinaryTree;

public class MyFileReader {
	/**
	 * Constructor, used to initialize parameters,load in the file
	 * @param importFile
	 */
	public MyFileReader(Reader importFile){
		this.tempStr=null;
		this.strContentReader=null;
		this.reader=importFile;
		
	}
	public void txtFileReader(){
		
	}
	public void fileReader() throws IOException {
		// Initialize the bufferReader ,load the file reader's instance
		this.strContentReader = new BufferedReader(this.reader);
		// Check whether the file is empty,if not, read string line by line
		while ((tempStr = strContentReader.readLine()) != null) {
			// delete the head and tail whitespaces which were read by readline function
			tempStr = tempStr.trim();
			//Read-in string checker
			switch(tempStr){
			case "INSERT":
				this.binaryTree=new BinaryTree();
				break;
			case "TRAVERS L-R POSTORDER":
				binaryTree.postOrderTraversal();
				break;
			case "TRAVERS L-R INORDER":
				binaryTree.inOrderTraversal();
				break;
			case"TRAVERS L-R PREORDER":
				binaryTree.preOrederTraversal();
				break;
			case"TRAVERS R-L INORDER":
				binaryTree.RtoLinOrderTraversal();
				default:
					binaryTree.insert(tempStr);
					System.out.println("this is current read in data  "+tempStr);
					break;
			}

			}
		}
	/**
	 * Parameters
	 */
	private BufferedReader strContentReader;
	private String tempStr;
	private Reader reader;
	private BinaryTree binaryTree;

}
